package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormEquipmentModifyServerDetail;
import com.glsc.ngateway.common.base.domainmapper.FlowFormEquipmentModifyServerDetailMapper;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.equipment.domainDto.FlowFormEquipmentModifyServerDetailDto;
import org.apache.logging.log4j.util.Strings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * FlowFormEquipmentModifyServerDetail转换器
 *
 * @author xuchang
 */
public class FlowFormEquipmentModifyServerDetailConverter extends AbstractFlowFormDataConverter {
    public static FlowFormEquipmentModifyServerDetailDto do2Dto(FlowFormEquipmentModifyServerDetail modifyServerDetail) {
        if (Objects.isNull(modifyServerDetail)) {
            return null;
        }
        FlowFormEquipmentModifyServerDetailDto applyDto = FlowFormEquipmentModifyServerDetailMapper.INSTANCE.domain2dto(modifyServerDetail);
        applyDto.setIpList(Strings.isBlank(modifyServerDetail.getIpListStr()) ? new ArrayList<>(0)
                : Arrays.stream(modifyServerDetail.getIpListStr().split(",")).collect(Collectors.toList()));
        applyDto.setIpListModified(Strings.isBlank(modifyServerDetail.getIpListModifiedStr()) ? new ArrayList<>(0)
                : Arrays.stream(modifyServerDetail.getIpListModifiedStr().split(",")).collect(Collectors.toList()));
        return applyDto;
    }

    public static List<FlowFormEquipmentModifyServerDetailDto> do2Dto(List<FlowFormEquipmentModifyServerDetail> modifyServerDetailList) {
        return CollectionUtils.isEmpty(modifyServerDetailList) ? java.util.Collections.emptyList() : modifyServerDetailList.stream().map(FlowFormEquipmentModifyServerDetailConverter::do2Dto).collect(Collectors.toList());
    }

    public static FlowFormEquipmentModifyServerDetail dto2Do(FlowFormEquipmentModifyServerDetailDto modifyServerDetailDto) {
        if (Objects.isNull(modifyServerDetailDto)) {
            return null;
        }
        FlowFormEquipmentModifyServerDetail apply = FlowFormEquipmentModifyServerDetailMapper.INSTANCE.dto2domain(modifyServerDetailDto);
        apply.setIpListStr(CollectionUtils.isEmpty(modifyServerDetailDto.getIpList()) ? Strings.EMPTY
                : String.join(",", modifyServerDetailDto.getIpList()));
        apply.setIpListModifiedStr(CollectionUtils.isEmpty(modifyServerDetailDto.getIpListModified()) ? Strings.EMPTY
                : String.join(",", modifyServerDetailDto.getIpListModified()));
        return apply;
    }

    public static List<FlowFormEquipmentModifyServerDetail> dto2Do(List<FlowFormEquipmentModifyServerDetailDto> modifyServerDetailDtoList) {
        return CollectionUtils.isEmpty(modifyServerDetailDtoList) ? java.util.Collections.emptyList() : modifyServerDetailDtoList.stream().map(FlowFormEquipmentModifyServerDetailConverter::dto2Do).collect(Collectors.toList());
    }

}
